<?php
/**
 *根据分类ID获取文章
 *获取热门新闻，按照点击量
 *$classid  分类ID
 *$num	获取条数
 *$findkeyStr 1 推荐
 *$flag  获取类型     new 是只获取新闻  不写就是按照分类取回来数据
 *$order 按照那个字段排序 默认是ID
 *$orderby 排序方式
 */
function getCateGory($classid,$num,$findkeyStr="",$flag='',$order,$orderby='+',$page='1'){
	//获取下级所有ID
	$CataLog = new CataLog();
	$nameClassArray = $CataLog->getCatalogSon($classid);
	if(empty($nameClassArray)){
		$nameClassArray = $CataLog->lookRoleModule($classid);
		$data[$nameClassArray['id']]['title'] = $nameClassArray['text'];
		$data[$nameClassArray['id']]['dir'] = CREATEHTML ? nameClassAndId($nameClassArray) :'/column.php?classid='.$nameClassArray['id'];
		$data[$nameClassArray['id']]['sid'] = $nameClassArray['id'];
	}else{
		if(is_array($nameClassArray)){
			foreach($nameClassArray as $key=>$value){
				$nameClassArray = $CataLog->Rolefzid ($value['id']);
				$idData[] = $value['id'];
				if(is_array($nameClassArray)){
					foreach($nameClassArray as $k=>$v){
						$idData[] = $v['id'];
					}
				}
				$data[$value['id']]['title'] = $value['text'];
				$data[$value['id']]['dir'] = CREATEHTML ? nameClassAndId($value) :'/column.php?classid='.$value['id'];
				$data[$value['id']]['sid'] = implode(',',$idData);
				unset($idData);
			}
		}
	}
	if(is_array($data)){
		foreach($data as $k=>$v){
			$findkey[] = 'classid in ('.$data[$k]['sid'].')';
			if(!empty($findkeyStr)){
				switch($findkeyStr){
					case 1:
					$findkey[] = "`flag` = '1'";
					break;
					case 2:
					$findkey[] = "`flag` = '2'";
					break;
				}
			}
			$dataArry['class'][$k] = $data[$k];
			$dataArry['class'][$k]['dataArray'] = $CataLog->getArctneList($page,$num,$findkey,$order,$fields='*',$orderby);
			unset($findkey);
			if(is_array($dataArry['class'][$k]['dataArray'])){
				foreach($dataArry['class'][$k]['dataArray'] as $j=>&$h){
					$dir_Path = nameArticleAndId($h);
					$h['dir'] = CREATEHTML ?  $dir_Path .date('Ymd',$h['pubdate']).'/'.$h['id'].'.html' : '/article.php?id='.$h['id'];
					$h['time'] = date('Y-m-d',$h['pubdate']);
					$h['classUrl'] = CREATEHTML ? $dir_Path :'/column.php?classid='.$h['classid'];
					$h['classname'] = '['.$h['classname'].']';
					$h['classTitle'] = $h['classname'];
					$h['classTitle'] = $h['classname'];
					$dataArry['new'][$h['id']] = $h;
				}
			}
		}
	}
	 
	if(is_array($dataArry['new'])){
		$dataArry['new'] = sysSortArray($dataArry['new'],'xdid',$SortOrder1 = "SORT_DESC",$SortType1 = "SORT_REGULAR");
		if('+'==$orderby && 'id'==$order){
			array_multisort($dataArry['new'], SORT_DESC);
		}
		if('new'==$flag){
			if(!empty($num)){
				array_splice($dataArry['new'], $num);
			}
			return $dataArry['new'];
		}
	}
	return $dataArry;
}
?>